package uw.illno.controller

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import uw.illno.pojo.Student
import uw.illno.service.AdministratorService


@Controller
class DeleteStudent {
    @Autowired
    private lateinit var service: AdministratorService

    @RequestMapping(value = ["/deletestu"], method = [RequestMethod.POST])
    fun dstu(model: Model, sno: String): String {

        when (sno) {
            "" -> {
                model.addAttribute("msgd", "学号不能为空！")
                return "adpages/adminindex"
            }
            else -> {
                val s = Student()
                s.sno = sno
                val r = service.delete_student(s)
                return if (r > 0) {
                    model.addAttribute("msgd1", "成功删除该学生！")
                    "adpages/adminindex"
                } else {
                    model.addAttribute("msgd", "该学生不存在！")
                    "adpages/adminindex"
                }

            }
        }

    }
}